<template>
  <div :style="newStyle">
    <span v-if="$attrs.onlyShow">{{modelValue}}</span>
    <el-input-number
      v-else
      ref="elInputNumber"
      v-model="formValue"
      v-bind="$attrs"
      @input="onInput"
      @blur="onBlur"
      @change="onChange"
      @focus="handleFocus"
    />
  </div>
</template>

<script>
import { comMixin } from "../../../utils/comMixins";
export default {
  mixins: [comMixin],
  name: "form-input-number",
  model: {
    prop: "value", // 绑定的值，通过父组件传递
    event: "update",
  },
  props: {
    modelValue: {
      type: [String, Number],
      default: "",
    },
  },
  computed: {
    formValue: {
      get() {
        return this.modelValue;
      },
      set(val) {
        this.$emit("update", val);
      },
    },
  },
  methods: {
    handleFocus() {
      this.onFocus();
      if (this.$attrs.readonly) this.$refs.elInputNumber.$refs.input.blur();
    },
  },
};
</script>

<style lang="scss" scoped></style>
